require('./PageHome.styl');
const classNames = require("classnames")
const reactMixin = require('react-mixin');
const Actions = require('./actions');
const Store = require('./store');
import { Control } from 'react-keeper';
import { Boxs, NavBar } from 'saltui';
import ui from 'clientConfig/util/jsapi/ui';
const { HBox, Box, VBox } = Boxs;
const Rollup = require('components/rollup');
const Listitem = require('components/listitem');
const WithRefresh = require('components/withrefresh');
const PendingList = require('components/pendinglist');
const ListWithEvaluate = WithRefresh(
    PendingList,
    (pageNum, props, success, error) => {
        Actions.fetchEvaluteList(pageNum, props, success, error)
    }
);
class Home extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            listdata: [],
            classId: '',
            title:''
        };
        this.handleOnLeftClick = this.handleOnLeftClick.bind(this)
        this.handleOnRightClick = this.handleOnRightClick.bind(this);
        this.refresh = this.refresh.bind(this);
    }
    handleOnLeftClick() {
        ui.close();
    }
    refresh(classId) {
        let t = this;
        for (let item of this.state.listdata) {
            if (item.classId == classId) {
                var title = item.title;
            }
        }
        this.setState({ classId,title }, () => {
            t.refs.ListWithEvaluate.onRefresh()
        })
    }
    //右侧导航按钮
    handleOnRightClick() {
        Control.go('/home/addevaluate/' + 'add');
    }
    render() {
        let t = this;
        return (
            <div className="home">
                <NavBar
                    className={classNames({"ios-nav-bar":window.isIphone})}
                    isShow={false}
                    title='评价'
                    onLeftClick={this.handleOnLeftClick.bind(this)}
                    onRightClick={this.handleOnRightClick.bind(this)}
                    rightText='添加'
                />
                {this.state.classId &&
                    <Rollup
                        type="class"
                        title={this.state.title}
                        listdata={this.state.listdata}
                        refresh={this.refresh}
                    />}
                {this.state.classId &&
                    <ListWithEvaluate
                        className="msg"
                        ref="ListWithEvaluate"
                        leftSlip={false}
                        classId={this.state.classId}
                        type="teacher"
                    />
                }
            </div>
        );
    }

    componentWillMount() {
    }

    componentDidMount() {
        Actions.getClassList()
    }

    componentWillReceiveProps(nextProps) {
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {

    }
}
reactMixin.onClass(Home, Reflux.connect(Store));
module.exports = Home;
